package xiaye.crawler.core;

import javax.persistence.EntityManager;
import javax.persistence.Persistence;

import xiaye.crawler.core.impl.BulletLinkParser;
import xiaye.crawler.core.impl.DbPageStore;
import xiaye.crawler.core.impl.PrinterPageStore;
import xiaye.crawler.core.impl.SimpleCrawler;
import xiaye.crawler.core.impl.SimpleCrawlerThread;
import xiaye.crawler.core.impl.SimpleFrontier;
import xiaye.crawler.domain.Page;

import com.google.inject.AbstractModule;
import com.google.inject.Singleton;

public class CrawlerModule extends AbstractModule {
	@Override
	public void configure(){
		bind(Page.class);
		bind(LinkParser.class).to(BulletLinkParser.class);
		bind(Frontier.class).to(SimpleFrontier.class).in(Singleton.class);
		bind(PageStore.class).to(DbPageStore.class).in(Singleton.class);
		bind(Crawler.class).to(SimpleCrawler.class).in(Singleton.class);
		bind(CrawlerThread.class).to(SimpleCrawlerThread.class);
		bind(HttpFetcher.class);
		bind(EntityManager.class).toInstance(Persistence.createEntityManagerFactory("crawler").createEntityManager());
	}
}
